import axios from 'axios'
import Assert from '../common/Assert.js'

export class CaseDecreaseService {
    static caseDecreaseService = null
    requestUrl = 'http://localhost/decreases'

    static getInstance(){
        if(this.caseDecreaseService == null){
            this.caseDecreaseService = new CaseDecreaseService()
        }
        return this.caseDecreaseService
    }

    /**
     * 根据案件id查询总申请减免金额
     * @param lawId
     */
    getTotalByLaw(lawId){
        return axios.get(`${this.requestUrl}/total/${lawId}`)
    }

    listsq(params){
        return axios.get(`${this.requestUrl}/listsq`,{
            params
        })
    }

    /**
     * 验证表单数据是否合法
     * @param caseDecrease
     */
    check(caseDecrease){
        return !(!Assert.isNotNull(caseDecrease.decreaseMoney, '请输入减免金额')
            || !Assert.isLessZero(caseDecrease.decreaseMoney, '请输入合法的金额'));
    }

    /**
     * 根据wid查找费用减免
     */
    selectByCaseLaw(a){
        return axios.get(`${this.requestUrl}/selectByCaseLaw`,{
            params:a
        })
    }

    selectIdforMoneymoney(id){
        return axios.get(`${this.requestUrl}/caselawid/${id}`)
    }

    /**
     * 提交的方法
     * @param caseDecrease
     */
    save(caseDecrease){
        return axios.post(this.requestUrl,caseDecrease)
    }

    /**
     * 分页查询费用减免记录
     * @param params
     */
    getByPage(params){
        return axios.get(`${this.requestUrl}/page`,{
            params
        })
    }

    /**
     * 根据案件id查询
     * @param id
     */
    getByCaseLaw(id){
        return axios.get(`${this.requestUrl}/law/${id}`)
    }
}